package com.huiqiao.stat.controller;

import com.huiqiao.stat.domain.BaseEntity;
import com.huiqiao.stat.service.StatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: yanliwei@foolish
 * @CreateTime: 2024-12-25  09:13
 */

@Controller
@RequestMapping("stat")
public class StatController {

    @Autowired
    private StatService statService;

    /**
     * 跳转到客户地区统计⻚⾯
     */
    @RequestMapping("toCustomerAreaStat")
    public String toCustomerAreaStat(){
        return "stat/customerAreaStat";
    }


    /**
     * 跳转到年度月份销售额
     * @author: yanliwei@foolish
     * @date: 2024/12/25 星期三 10:30
     */
    @RequestMapping("toCompanyYearGradeStat")
    public String toCompanyYearGradeStat(){
        return "stat/companyYearGradeStat";
    }

    /**
     * 跳转到公司年度业务统计
     * @author: yanliwei@foolish
     * @date: 2024/12/25 星期三 10:15
     */
    @RequestMapping("toOpernameYearGradeStat")
    public String toOpernameYearGradeStat(){
        return "stat/opernameYearGradeStat";
    }


    /**
     * 加载客户地区数据
     * @return
     */
    @RequestMapping("loadCustomerAreaStatJson")
    @ResponseBody
    public List<BaseEntity> loadCustomerAreaStatJson(){

        return this.statService.loadCustomerAreaStatList();
    }

    /**
     * 加载业务员年度业务统计
     * @author: yanliwei@foolish
     * @date: 2024/12/25 星期三 10:15
     */
    @RequestMapping("loadOpernameYearGradeStatJson")
    @ResponseBody
    public Map<String, Object> loadOpernameYearGradeStatJson(String year) {
        List<BaseEntity> entities = this.statService.loadOpernameYearGradeStatList(year);
        Map<String, Object> map = new HashMap<String, Object>();
        List<String> names = new ArrayList<String>();
        List<Double> values = new ArrayList<Double>();
        for (BaseEntity baseEntity : entities) {
            names.add(baseEntity.getName());
            values.add(baseEntity.getValue());
        }
        map.put("name", names);
        map.put("value", values);
        return map;
    }

    /**
     * 加载年度销售额数据
     * @author: yanliwei@foolish
     * @date: 2024/12/25 星期三 10:32
     */
    @RequestMapping("loadCompanyYearGradeStatJson")
    @ResponseBody
    public List<Double> loadCompanyYearGradeStatJson(String year) {
        List<Double> entities = this.statService.loadCompanyYearGradeStatList(year);
        for (int i = 0; i < entities.size(); i++) {
            if (null == entities.get(i)) {
                entities.set(i, 0.0);
            }
        }
        return entities;
    }




}
